#!/bin/bash

# brew install gdu && ln -sfn $(brew --prefix)/bin/gdu-go $(brew --prefix)/bin/gdu
# brew install node && npm config set registry https://registry.npmmirror.com
# brew install neovim neovide python3 node wget eza bat lsd fd fzf ripgrep bottom lazygit zoxide luarocks &
# python3 -m pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple

# brew install fzf && $(brew --prefix)/opt/fzf/install --completion --key-bindings --update-rc --no-bash --no-fish

#bese_url="https://mirror.nju.edu.cn/github-release/neovim/neovim/LatestRelease/"

bese_url="https://gitee.com/hevey88/a4_user/releases/download/"
version="0.10.4"

if [[ "$(uname -s)" == "Darwin" ]]; then
	file_name="nvim-macos-$(uname -m).tar.gz"
	dir_name="nvim-macos-$(uname -m)"
fi

if [[ "$(uname -s)" == "Linux" ]]; then

	if [[ "$(uname -m)" == "aarch64" ]]; then
		bese_url="https://gitee.com/hevey88/kitty/releases/download/"
		version="v0.10.0"
		file_name="nvim-linux-arm64.tar.bz"
		dir_name="nvim-linux-arm64"
		# https://gitee.com/hevey88/kitty/releases/download/v0.10.0/nvim-linux-arm64.tar.bz

	elif [[ "$(uname -m)" == "x86_64" ]]; then
		file_name="nvim-linux-$(uname -m).tar.gz"
		dir_name="nvim-linux-$(uname -m)"
	fi

fi

url=$bese_url$version"/"$file_name

mkdir -p ~/.config
curl -SsL "$url" -o ~/.config/$file_name
tar xf ~/.config/$file_name -C ~/.config/
mkdir -p ~/.local/bin/ ~/.local/share/man/man1
ln -sf ~/.config/$dir_name/bin/nvim ~/.local/bin/
ln -sf ~/.config/$dir_name/share/man/man1/nvim.1 ~/.local/share/man/man1
sudo mkdir -p /usr/local/bin/
sudo ln -sf ~/.config/$dir_name/bin/nvim /usr/local/bin/

if [[ "$(uname -s)" == "Linux" ]]; then
	sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/nvim 1
	sudo update-alternatives --set editor /usr/local/bin/nvim
fi

rm -rf ~/.config/$file_name

: <<COMMENT

bash -c "$(curl -fsSL https://gitee.com/hevey88/install_script/raw/main/install_neovim.sh)"

COMMENT
